package hikari.gui.panels.bullet;

import com.gooddies.swing.RowLayout;
import com.gooddies.wiring.annotations.WiringComponent;
import hikari.gui.guicomponents.hLabel;
import hikari.gui.panels.particle.Vector3dEditor;
import hikari.hcomponents.physics.BoxRigidBody;
import hikari.hcomponents.physics.PhysicsData;
import hikari.managers.Manager3D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.swig.jirr.aabbox3df;
import org.swig.jirr.vector3df;

/**
 * @author sad
 */
@WiringComponent()
public class BulletBoxRigidBodyPanel extends IBulletRigidBodyEditPanel {

    private Vector3dEditor sizeEB;
    private BoxRigidBody rigidBody;

    public BulletBoxRigidBodyPanel() {
        setTitle("Box Rigidbody");
    }
    
    public void init(PhysicsData data){
    this.data = data;
        rigidBody = (BoxRigidBody) data.getRigidBody();
        setLayout(new RowLayout().setStartYGap(20).setStartXGap(10).setEndYGap(10));
        add(new hLabel("Size"), RowLayout.NewRow);

        sizeEB = new Vector3dEditor(this);
        sizeEB.setValueChangedEvent(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                onSizeChanged(sizeEB.getValue());
            }
        });
        sizeEB.setValue(rigidBody.getSize());
    }

    private void onSizeChanged(vector3df size) {
        rigidBody.setSize(size);
    }

    private aabbox3df create3dBox(vector3df size) {
        aabbox3df box = new aabbox3df(-size.getX(), -size.getY(), -size.getZ(), size.getX(), size.getY(), size.getZ());
        box.setMaxEdge(box.getMaxEdge());
        return box;
    }

    @Override
    public void drawGizmo(Manager3D manager) {
        manager.getVideoDriver().draw3DBox(create3dBox(rigidBody.getSize()));
    }
}
